package com.esri.android.map.osm;

import android.util.Log;
import com.esri.android.map.TiledServiceLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.a;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;

/* loaded from: classes.dex */
public class OpenStreetMapLayer extends TiledServiceLayer {
    public static final double XMAX = 2.003750834278E7d;
    public static final double XMIN = -2.003750834278E7d;
    public static final double YMAX = 2.003750834278E7d;
    public static final double YMIN = -2.003750834278E7d;
    private static final int s = 256;
    private static final int t = 256;
    private static final double[] u = {156543.0339279998d, 78271.5169639999d, 39135.7584820001d, 19567.8792409999d, 9783.93962049996d, 4891.96981024998d, 2445.98490512499d, 1222.99245256249d, 611.49622628138d, 305.748113140558d, 152.874056570411d, 76.4370282850732d, 38.2185141425366d, 19.1092570712683d, 9.55462853563415d, 4.77731426794937d, 2.38865713397468d, 1.19432856685505d, 0.597164283559817d, 0.298582141647617d, 0.149291070823808d, 0.074645535411904d, 0.037322767705952d, 0.018661383985268d};
    private static final double[] v = {5.91657527591555E8d, 2.95828763795777E8d, 1.47914381897889E8d, 7.3957190948944E7d, 3.6978595474472E7d, 1.8489297737236E7d, 9244648.868618d, 4622324.434309d, 2311162.217155d, 1155581.108577d, 577790.554289d, 288895.277144d, 144447.638572d, 72223.819286d, 36111.909643d, 18055.954822d, 9027.977411d, 4513.988705d, 2256.994353d, 1128.497176d, 564.248588d, 282.124294d, 141.062147d, 70.531074d};
    private static String[] w = {"http://a.tile.openstreetmap.org", "http://b.tile.openstreetmap.org", "http://c.tile.openstreetmap.org"};
    private static String x = "<a href=\"http://www.openstreetmap.org/\">Map tiles from OpenStreetMap</a>";
    private String[] c;
    private int d;
    private int e;
    private String f;
    private int g;

    public OpenStreetMapLayer() {
        this(true);
    }

    public OpenStreetMapLayer(boolean z) {
        this(w, 0, 18, x, z);
    }

    public OpenStreetMapLayer(String[] strArr, int i, int i2, String str, boolean z) {
        super(z);
        this.g = 0;
        a(strArr, i, i2, str, z);
    }

    private void a(String[] strArr, int i, int i2, String str, boolean z) {
        if (strArr == null || strArr.length < 0) {
            throw new IllegalArgumentException("Tile server URLs cannot be null or empty");
        }
        if (i < 0 || i > i2 || i2 > u.length) {
            throw new IllegalArgumentException("minimum or maximum zoom levels are not set correctly");
        }
        String[] strArr2 = new String[strArr.length];
        this.c = strArr2;
        System.arraycopy(strArr, 0, strArr2, 0, strArr.length);
        this.d = i;
        this.e = i2;
        this.f = str;
        this.g = 0;
        if (z) {
            try {
                getServiceExecutor().submit(new Runnable() { // from class: com.esri.android.map.osm.OpenStreetMapLayer.1
                    @Override // java.lang.Runnable
                    public void run() {
                        OpenStreetMapLayer.this.initLayer();
                    }
                });
            } catch (RejectedExecutionException e) {
                Log.e(a.a, "initialization of the layer failed.", e);
            }
        }
    }

    public String[] getTileServerURLs() {
        return this.c;
    }

    public int getMinZoomLevel() {
        return this.d;
    }

    public int getMaxZoomLevel() {
        return this.e;
    }

    public String getAttributionText() {
        return this.f;
    }

    public void setKey(String str) {
        if (str == null || this.c == null) {
            return;
        }
        ArrayList arrayList = new ArrayList(this.c.length);
        for (String str2 : this.c) {
            arrayList.add(str2.replaceAll("\\{KEY\\}", str));
        }
        this.c = (String[]) arrayList.toArray(new String[0]);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.esri.android.map.TiledServiceLayer, com.esri.android.map.Layer
    public void initLayer() {
        if (getID() == 0) {
            this.nativeHandle = create();
        }
        if (getID() == 0) {
            changeStatus(OnStatusChangedListener.STATUS.fromInt(-1000));
            Log.e(a.a, "name =" + getName());
            return;
        }
        try {
            int i = this.e;
            double[] dArr = new double[i];
            double[] dArr2 = new double[i];
            System.arraycopy(u, 0, dArr, 0, i);
            System.arraycopy(v, 0, dArr2, 0, this.e);
            setDefaultSpatialReference(SpatialReference.create(102100));
            setFullExtent(new Envelope(-2.003750834278E7d, -2.003750834278E7d, 2.003750834278E7d, 2.003750834278E7d));
            setTileInfo(new TiledServiceLayer.TileInfo(new Point(-2.003750834278E7d, 2.003750834278E7d), dArr2, dArr, i, 96, 256, 256));
            super.initLayer();
        } catch (Exception e) {
            changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_OSM_LAYER));
            Log.e(a.a, "OSM map name =" + getName(), e);
        }
    }

    @Override // com.esri.android.map.TiledServiceLayer
    protected byte[] getTile(int i, int i2, int i3) throws Exception {
        if (i < this.d || i > this.e) {
            return new byte[0];
        }
        String[] strArr = this.c;
        int i4 = this.g;
        int i5 = i4 + 1;
        this.g = i5;
        String str = strArr[i4];
        this.g = i5 < strArr.length ? i5 : 0;
        return com.esri.core.internal.io.handler.a.a(str + "/" + i + "/" + i2 + "/" + i3 + ".png", (Map<String, String>) null);
    }
}
